package cn.linjianhui.thread.error;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;

public class ArrayListMultiThread {
//    static List<Integer> al = new ArrayList<>(10);

    // 线程安全
    static Vector<Integer> al = new Vector<>(10);

    public static class AddThread implements Runnable {

        @Override
        public void run() {
            for(int i = 0; i < 10000; i++) {
                al.add(i);
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
//        al = Collections.synchronizedList(al);
        Thread t1 = new Thread(new AddThread());
        Thread t2 = new Thread(new AddThread());
        t1.start(); t2.start();
        t1.join(); t2.join();
        System.out.println(al.size());
    }
}
